﻿/* Write a program that extracts from a given text all sentences containing given word.
		Example: The word is "in". The text is:
We are living in a yellow submarine. We don't have 
anything else. Inside the submarine is very tight.
So we are drinking all day. We will move out in 5 days.

 * Expected result:
 We are living in a yellow submarine.
 We will move out in 5 days.
 * Consider that the sentences are separated by "." and the words - by non-letter symbols.
 */
using System;
using System.Text.RegularExpressions;

namespace _8.Extract
{
    class Extract
    {
        static void Main()
        {
            Console.Write("Enter a string: ");
            string str = Console.ReadLine();
            Console.Write("Enter a word to search for: ");
            string pword = Console.ReadLine();
            //string str = "We are living in a yellow submarine. We don't have anything else. Inside the submarine is very tight. So we are drinking all the day. We will move out in 5 days.";
            //string pword = "in"; //pattern word
            Regex r = new Regex(@"((\s*?)[^\.]*)\b\s" + pword + @"\b.*?\.", RegexOptions.IgnoreCase);
            Console.WriteLine("I found the following sentences with Occurances of {0}: ", pword);
            foreach (Match m in r.Matches(str))
            {
                Console.WriteLine(m.Groups[0].Value.ToString());
            }
        }
    }
}
